<?php

namespace App\Http\Controllers\Backstage\Company;

use App\Ant\Excel\Imports\ArchiveImport;
use App\Ant\WithUpload;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Backstage\Company\Archive\UploadRequest;
use App\Models\Company\Archive;
use App\Transformers\Company\ArchiveTransformer;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class ArchiveController extends BaseController
{
    use WithUpload;

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $page_size = get_request_page();
        $articles = Archive::where('is_state', true)->paginate($page_size);
        return $this->response->paginator($articles, new ArchiveTransformer());
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function upload(UploadRequest $request)
    {
        $file = $this->addUpload($request);
        Excel::import(new ArchiveImport(), $file->path);
        return $this->response->noContent();
    }
}
